package com.nowcoder.Offer.Array;

import org.junit.Test;

/**
 * 旋转数组的最小值
 */
public class FindMinInRotateArray {

    public int minNumberInRotateArray(int [] array) {
        if(array == null || array.length == 0) return 0;
        int l = 0, r = array.length - 1;
        while(l<r){
            int mid = (l + r) >>> 1;
            if(array[mid] < array[r])
                r = mid;
            else if(array[mid] > array[r])
                l = mid + 1;
            else
                r --;
        }
        return array[l];
    }

    @Test
    public void test(){
        int[] arr = {3,4,5,1,2};
        System.out.println(minNumberInRotateArray(arr));
    }


}
